package com.tzy.newbank.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

public class JwtUtils {
    //使用HS256算法生成jwt密钥。
    public static String createJWT(Map<String,Object> cliams){
        return Jwts.builder()
                .signWith(SignatureAlgorithm.HS256, "myMessage")
                .setClaims(cliams)
                .setExpiration(new Date(System.currentTimeMillis() + 10 * 60 * 1000))
                .compact();
    }

    public static Claims readJWT(String myMessage){
        return Jwts.parser()
                .setSigningKey("myMessage")
                .parseClaimsJws(myMessage)
                .getBody();
    }

}
